<template>
  <div class="app-container">
    <div style="width: 20%; margin: 20px auto; font-weight: bold">
      银西运用车间检修作业计划
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="130px">
      <div style="width: 50%; margin: auto">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="编号" prop="code">
              <el-input
                type="textarea"
                autosize
                :disabled="disabled"
                placeholder="请输入编号"
                v-model="form.code"
                maxlength="30"
                show-word-limit
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期" prop="jobDate">
              <el-date-picker
                clearable
                :disabled="disabled"
                v-model="form.jobDate"
                type="date"
                style="width: 280px"
                value-format="yyyy-MM-dd"
                placeholder="请选择日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="班次" prop="shift">
              <el-radio-group v-model="shift" :disabled="disabled">
                <el-radio label="1">白班</el-radio>
                <el-radio label="2">夜班</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车间编制人" prop="workshopOrganizer">
              <el-input
                type="textarea"
                autosize
                :disabled="disabled"
                placeholder="请输入车间编制人"
                v-model="form.workshopOrganizer"
                maxlength="30"
                show-word-limit
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="车间审核人" prop="workshopAuditor">
              <el-input
                type="textarea"
                autosize
                :disabled="disabled"
                placeholder="请输入车间审核人"
                v-model="form.workshopAuditor"
                maxlength="30"
                show-word-limit
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div class="titlesplan">
        <div>作业内容·非库外配合作业</div>
        <div class="buttonsplan" v-if="!disabled">
          <el-button type="primary" size="mini" @click="NoneAddPlans">新增</el-button>
        </div>
      </div>
      <el-table :data="noOuterData" style="width: 100%">
        <el-table-column prop="date" label="序号" type="index" width="55">
        </el-table-column>
        <el-table-column
          prop="carName"
          label="编组号"
          min-width="150"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="intoTrains"
          label="终到车次/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="washingWay"
          label="洗车方式/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="waterLanes"
          label="吸污上水股道/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="trackNames"
          label="股道/台位"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="workTeamName"
          label="作业班组"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="preview"
          label="供电预检"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="powerOutages"
          label="断电作业"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="powerSupply"
          label="供电作业"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="jobContent"
          label="作业内容"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="jointTime"
          label="联检时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="runningTrains"
          label="开行车次/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <div v-if="!disabled">
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
            width="80"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                class="delBtn_R"
                @click="handleDeleteNoplan(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </div>
      </el-table>
      <div class="titlesplan titlesplanTwo">
        <div>作业内容·库外配合作业</div>
        <div class="buttonsplan" v-if="!disabled">
          <el-button type="primary" @click="AddPlans" size="mini">新增</el-button>
        </div>
      </div>
      <el-table :data="OuterData" style="width: 100%">
        <el-table-column prop="date" label="序号" type="index" width="55">
        </el-table-column>
        <el-table-column
          prop="carName"
          label="编组号"
          min-width="150"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="intoTrains"
          label="终到车次/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="washingWay"
          label="洗车方式/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="waterLanes"
          label="吸污上水股道/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="trackNames"
          label="股道/台位"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="workTeamName"
          label="作业班组"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="preview"
          label="作业时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="jobContent"
          label="作业内容"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="jointTime"
          label="联检时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="runningTrains"
          label="开行车次/时间"
          min-width="180"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <div v-if="!disabled">
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            fixed="right"
            width="80"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                class="delBtn_R"
                @click="handleDeleteNoplanOuter(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </div>
      </el-table>
      <div class="secondTitle">运用存车场送车人员</div>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="动车组送车负责人" prop="deliveryPersonnel">
            <el-input
              :disabled="disabled"
              type="textarea"
              autosize
              placeholder="请输入内容"
              v-model="form.deliveryPersonnel"
              maxlength="30"
              show-word-limit
              style="width: 80%"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电话" prop="deliveryPersonnelTel">
            <el-input
              :disabled="disabled"
              style="width: 80%"
              placeholder="请输入电话"
              v-model="form.deliveryPersonnelTel"
              maxlength="11"
              show-word-limit
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="secondTitle">动车组日常维护</div>
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form-item label="" prop="maintenance">
            <el-input
              :disabled="disabled"
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="form.maintenance"
              maxlength="100"
              show-word-limit
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="secondTitle">其他注意事项</div>
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form-item label="" prop="attention">
            <el-input
              :disabled="disabled"
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="form.attention"
              maxlength="100"
              show-word-limit
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="footersPlan">
      <div></div>
      <div>
        <el-button
          type="primary"
          @click="handleAdd"
          size="medium"
          style="margin-right: 6px"
          >确定</el-button
        >
        <el-button @click="handleCancel" size="medium" style="margin-right: 6px"
          >取消</el-button
        >
      </div>
    </div>

    <!-- 添加非库外配合作-->
    <el-dialog title="作业内容-新增" :visible.sync="open" width="1000px" append-to-body>
      <el-form
        ref="formnoOuterWorkPlan"
        :model="formnoOuterWorkPlan"
        :rules="rulesnoOuterWorkPlan"
        label-width="140px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="编组号" prop="carId">
              <el-select
                v-model="formnoOuterWorkPlan.carId"
                clearable
                style="width: 220px"
                @change="selectcarIds"
              >
                <el-option
                  v-for="dict in choiceLists"
                  :key="dict.id"
                  :label="dict.code"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="终到车次/时间" prop="intoTrains">
              <el-input
                v-model="formnoOuterWorkPlan.intoTrains"
                placeholder="请输入洗车方式/时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="吸污上水股道/时间" prop="waterLanes">
              <el-input
                v-model="formnoOuterWorkPlan.waterLanes"
                placeholder="请输入洗车方式/时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="洗车方式/时间" prop="washingWay">
              <el-input
                v-model="formnoOuterWorkPlan.washingWay"
                placeholder="请输入洗车方式/时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="股道/台位" prop="trackIds" ref="trackIds">
              <el-select v-model="trackIds" clearable multiple style="width: 220px">
                <el-option
                  v-for="dict in trackTeamLists"
                  :key="dict.id"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="作业班组" prop="workTeamId">
              <el-select
                v-model="formnoOuterWorkPlan.workTeamId"
                clearable
                style="width: 220px"
                @change="selectWorkTeam"
              >
                <el-option
                  v-for="dict in workTeamchoiceLists"
                  :key="dict.id"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <div style="width: 7%; margin: auto">作业时间</div>
        <div class="worksplans">
          <div class="palnscontents">
            <div style="margin-bottom: 10px; margin-left: 130px">供电作业</div>
            <div>
              <el-form-item prop="powerSupply">
                <el-input
                  v-model="formnoOuterWorkPlan.powerSupply"
                  placeholder="请输入内容"
                  type="textarea"
                  autosize
                  maxlength="20"
                  show-word-limit
                />
              </el-form-item>
            </div>
          </div>
          <div class="palnscontents">
            <div style="margin-bottom: 10px; margin-left: 130px">断电作业</div>
            <div>
              <el-form-item prop="powerOutages">
                <el-input
                  v-model="formnoOuterWorkPlan.powerOutages"
                  placeholder="请输入内容"
                  type="textarea"
                  autosize
                  maxlength="20"
                  show-word-limit
                />
              </el-form-item>
            </div>
          </div>
          <div class="palnscontents">
            <div style="margin-bottom: 10px; margin-left: 130px">供电预检作业</div>
            <div>
              <el-form-item prop="preview">
                <el-input
                  v-model="formnoOuterWorkPlan.preview"
                  placeholder="请输入内容"
                  type="textarea"
                  autosize
                  maxlength="20"
                  show-word-limit
                />
              </el-form-item>
            </div>
          </div>
        </div>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="作业内容" prop="jobContent">
              <el-input
                v-model="formnoOuterWorkPlan.jobContent"
                placeholder="请输入内容"
                type="textarea"
                :rows="5"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="联检时间" prop="jointTime">
              <el-input
                v-model="formnoOuterWorkPlan.jointTime"
                placeholder="请输入内容"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开行车次/时间" prop="runningTrains">
              <el-input
                v-model="formnoOuterWorkPlan.runningTrains"
                placeholder="请输入内容"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormnoOuterWorkPlan">确 定</el-button>
        <el-button @click="cancelnoOuterWorkPlan">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 库外配合作 -->
    <el-dialog
      title="作业内容-新增"
      :visible.sync="openplanwork"
      width="900px"
      append-to-body
    >
      <el-form
        ref="formOuterWork"
        :model="formOuterWork"
        :rules="formOuterWorkrules"
        label-width="130px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="编组号" prop="carId">
              <el-select
                v-model="formOuterWork.carId"
                @change="selectcarIdsOuter"
                clearable
                style="width: 220px"
              >
                <el-option
                  v-for="dict in choiceLists"
                  :key="dict.id"
                  :label="dict.code"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="终到车次/时间" prop="intoTrains">
              <el-input
                v-model="formOuterWork.intoTrains"
                placeholder="请输入终到车次/时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="洗车方式/时间" prop="washingWay">
              <el-input
                v-model="formOuterWork.washingWay"
                placeholder="请输入洗车方式/时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="吸污上水股道/时间" prop="waterLanes">
              <el-input
                v-model="formOuterWork.waterLanes"
                placeholder="请输入内容"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="股道/台位" prop="OuttrackIds" ref="OuttrackIds">
              <el-select v-model="OuttrackIds" clearable style="width: 220px" multiple="">
                <el-option
                  v-for="dict in trackTeamLists"
                  :key="dict.id"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="作业班组" prop="workTeamId">
              <el-select
                v-model="formOuterWork.workTeamId"
                clearable
                @change="selectWorkTeamOuter"
                style="width: 220px"
              >
                <el-option
                  v-for="dict in workTeamchoiceLists"
                  :key="dict.id"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="作业时间" prop="preview">
              <el-input
                v-model="formOuterWork.preview"
                placeholder="请输入作业时间"
                type="textarea"
                autosize
                maxlength="20"
                style="width: 220px"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="作业内容" prop="jobContent">
              <el-input
                v-model="formOuterWork.jobContent"
                placeholder="请输入作业内容"
                type="textarea"
                :rows="5"
                style="width: 90%"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="联检时间" prop="jointTime">
              <el-input
                v-model="formOuterWork.jointTime"
                placeholder="请输入联检时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开行车次/时间" prop="runningTrains">
              <el-input
                v-model="formOuterWork.runningTrains"
                placeholder="请输入联检时间"
                type="textarea"
                autosize
                style="width: 220px"
                maxlength="20"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormOuterWork">确 定</el-button>
        <el-button @click="cancelOuterWork">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  workTeamchoice,
  choiceList,
  trackTeam,
  addWorkPlan,
  getWorkPlan,
  updateWorkPlan,
} from "@/api/workPlan/workPlan";
import _ from "lodash";
export default {
  name: "WorkPlan",
  data() {
    return {
      OuterData: [],
      noOuterData: [],
      shift: "1",
      formOuterWorkrules: {
        // carId: [{ required: true, message: "编组号不能为空", trigger: "blur" }],
        OuttrackIds: [{ required: true, message: "股道台位不能为空", trigger: "blur" }],
        workTeamId: [{ required: true, message: "作业班组不能为空", trigger: "blur" }],
        jobContent: [{ required: true, message: "作业内容不能为空", trigger: "blur" }],
        preview: [{ required: true, message: "作业时间不能为空", trigger: "blur" }],
      },
      formOuterWork: {},
      OuttrackIds: [],
      OutertrackNames: "",
      trackIds: [],
      trackNames: "",
      formnoOuterWorkPlan: {},
      //非库外
      rulesnoOuterWorkPlan: {
        carId: [{ required: true, message: "编组号不能为空", trigger: "blur" }],
        intoTrains: [
          { required: true, message: "终到车次/时间不能为空", trigger: "blur" },
        ],
        washingWay: [
          { required: true, message: "洗车方式时间不能为空", trigger: "blur" },
        ],
        waterLanes: [
          { required: true, message: "吸污上水股道时间不能为空", trigger: "blur" },
        ],
        trackIds: [{ required: true, message: "股道台位不能为空", trigger: "blur" }],
        workTeamId: [{ required: true, message: "作业班组不能为空", trigger: "blur" }],
        jobContent: [{ required: true, message: "作业内容不能为空", trigger: "blur" }],
      },
      // 表单校验
      rules: {
        deliveryPersonnelTel: [
          {
            pattern: /^1[3|4|5|6|7|8][0-9]\d{8}$/,
            message: "输入正确的手机号",
          },
        ],
        code: [{ required: true, message: "编号不能为空", trigger: "blur" }],
        jobDate: [{ required: true, message: "日期不能为空", trigger: "blur" }],
        shift: [{ required: true, message: "班次不能为空", trigger: "blur" }],
        workshopOrganizer: [
          { required: true, message: "车间编制人不能为空", trigger: "blur" },
        ],
        workshopAuditor: [
          { required: true, message: "车间审核人不能为空", trigger: "blur" },
        ],
      },
      openplanwork: false,
      open: false,
      form: {},
      tableData: [],
      choiceLists: [],
      workTeamchoiceLists: [],
      trackTeamLists: [],
      tableDataOuter: [],
      selectIds: "",
      ways: "",
      disabled: false,
    };
  },
  created() {
    this.selectIds = this.$route.params.id;
    this.ways = this.$route.params.way;
    if (this.ways == "look") {
      this.disabled = true;
    }
    if (this.ways == "edit") {
      this.disabled = false;
    }
    this.getchoiceList();
    this.getworkTeamchoice();
    this.gettrackTeam();
    if (this.selectIds) {
      this.getPlanInfo();
    }
  },
  methods: {
    getPlanInfo() {
      getWorkPlan(this.selectIds).then((res) => {
        this.form = res.data;
        let tableData = [];
        tableData = res.data.noOuterWorkPlanDetails;
        tableData.forEach((item) => {
          if (typeof item.trackId == "string") {
            // 字符转数组
            item.trackId = item.trackId.split(",");
          }
        });
        for (let i = 0; i < tableData.length; i++) {
          for (let j = 0; j < this.choiceLists.length; j++) {
            if (tableData[i].carId == this.choiceLists[j].id) {
              tableData[i].carName = this.choiceLists[j].code;
            }
          }
        }
        for (let i = 0; i < tableData.length; i++) {
          for (let j = 0; j < this.workTeamchoiceLists.length; j++) {
            if (tableData[i].workTeamId == this.workTeamchoiceLists[j].id) {
              tableData[i].workTeamName = this.workTeamchoiceLists[j].name;
            }
          }
        }
        let tarcked = [];
        for (let i = 0; i < tableData.length; i++) {
          for (let j = 0; j < this.trackTeamLists.length; j++) {
            if (tableData[i].trackId[i] == this.trackTeamLists[j].id) {
              tarcked.push(this.trackTeamLists[j].name);
              let aa = tarcked.join(",");
              tableData[i].trackNames = aa;
            }
          }
        }
        this.tableData = tableData;
        this.noOuterData = [...this.tableData];
        let tableDataOuter = [];
        tableDataOuter = res.data.outerWorkPlanDetails;
        tableDataOuter.forEach((item) => {
          if (typeof item.trackId == "string") {
            item.trackId = item.trackId.split(",");
          }
        });
        for (let i = 0; i < tableDataOuter.length; i++) {
          for (let j = 0; j < this.choiceLists.length; j++) {
            if (tableDataOuter[i].carId == this.choiceLists[j].id) {
              tableDataOuter[i].carName = this.choiceLists[j].code;
            }
          }
        }
        for (let i = 0; i < tableDataOuter.length; i++) {
          for (let j = 0; j < this.workTeamchoiceLists.length; j++) {
            if (tableDataOuter[i].workTeamId == this.workTeamchoiceLists[j].id) {
              tableDataOuter[i].workTeamName = this.workTeamchoiceLists[j].name;
            }
          }
        }
        let tarckedOuter = [];
        for (let i = 0; i < tableDataOuter.length; i++) {
          for (let j = 0; j < this.trackTeamLists.length; j++) {
            if (tableDataOuter[i].trackId[i] == this.trackTeamLists[j].id) {
              tarckedOuter.push(this.trackTeamLists[j].name);
              let aa = tarckedOuter.join(",");
              tableDataOuter[i].trackNames = aa;
            }
          }
        }
        this.tableDataOuter = tableDataOuter;
        this.OuterData = [...this.tableDataOuter];
        this.shift = this.form.shift;
      });
    },
    handleDeleteNoplanOuter(row) {
      for (let i = 0; i < this.OuterData.length; i++) {
        if (row.id == this.OuterData[i].id) {
          this.OuterData.splice(i, 1);
        }
      }
    },
    selectWorkTeamOuter(e) {
      this.workTeamchoiceLists.forEach((item) => {
        if (e == item.id) {
          this.formOuterWork.workTeamName = item.name;
        }
      });
    },
    selectcarIdsOuter(e) {
      this.choiceLists.forEach((item) => {
        if (e == item.id) {
          this.formOuterWork.carName = item.code;
        }
      });
    },
    handleDeleteNoplan(row) {
      for (let i = 0; i < this.noOuterData.length; i++) {
        if (row.id == this.noOuterData[i].id) {
          this.noOuterData.splice(i, 1);
        }
      }
    },
    selectWorkTeam(e) {
      console.log(e);
      this.workTeamchoiceLists.forEach((item) => {
        if (e == item.id) {
          this.formnoOuterWorkPlan.workTeamName = item.name;
        }
      });
    },
    selectcarIds(e) {
      console.log(e);
      this.choiceLists.forEach((item) => {
        if (e == item.id) {
          this.formnoOuterWorkPlan.carName = item.code;
        }
      });
    },
    //库外提交
    submitFormOuterWork() {
         if (this.OuttrackIds.length > 0) {
         this.$refs['OuttrackIds'].clearValidate()
         _.unset(this.formOuterWorkrules, ["OuttrackIds"]);
      }else{
        this.formOuterWorkrules.OuttrackIds = [{ required: true, message: "股道/台位不能为空", trigger: "blur" }]
      }
      this.$refs["formOuterWork"].validate((valid) => {
        if (valid) {
          let OutertableId = 1;
          let OutertrackName = [];
          for (let i = 0; i < this.OuttrackIds.length; i++) {
            for (let j = 0; j < this.trackTeamLists.length; j++) {
              if (this.OuttrackIds[i] == this.trackTeamLists[j].id) {
                OutertrackName.push(this.trackTeamLists[j].name);
              }
            }
          }
          this.formOuterWork.trackNames = OutertrackName.join(",");
          this.formOuterWork.trackId = this.OuttrackIds.join(",");

          if (!this.formOuterWork.intoTrains) {
            this.formOuterWork.intoTrains = "-";
          }
          if (!this.formOuterWork.washingWay) {
            this.formOuterWork.washingWay = "-";
          }
          if (!this.formOuterWork.waterLanes) {
            this.formOuterWork.waterLanes = "-";
          }
          if (!this.formOuterWork.jointTime) {
            this.formOuterWork.jointTime = "-";
          }
          if (!this.formOuterWork.runningTrains) {
            this.formOuterWork.runningTrains = "-";
          }

          this.openplanwork = false;
          this.formOuterWork.id = OutertableId++;
          let params = {};
          params = JSON.parse(JSON.stringify(this.formOuterWork));
          this.tableDataOuter.push(params);
          this.OuterData = [...this.tableDataOuter];
        }
      });
    },
    //非库外
    submitFormnoOuterWorkPlan() {
      if (this.trackIds.length > 0) {
         this.$refs['trackIds'].clearValidate()
         _.unset(this.rulesnoOuterWorkPlan, ["trackIds"]);
      }else{
        this.rulesnoOuterWorkPlan.trackIds = [{ required: true, message: "股道/台位不能为空", trigger: "blur" }]
      }

      this.$refs["formnoOuterWorkPlan"].validate((valid) => {
        if (valid) {
          let tableId = 1;
          let trackName = [];
          console.log(this.trackIds);

          for (let i = 0; i < this.trackIds.length; i++) {
            for (let j = 0; j < this.trackTeamLists.length; j++) {
              if (this.trackIds[i] == this.trackTeamLists[j].id) {
                trackName.push(this.trackTeamLists[j].name);
              }
            }
          }
          this.formnoOuterWorkPlan.trackNames = trackName.join(",");
          this.formnoOuterWorkPlan.trackId = this.trackIds.join(",");

          if (!this.formnoOuterWorkPlan.powerOutages) {
            this.formnoOuterWorkPlan.powerOutages = "-";
          }
          if (!this.formnoOuterWorkPlan.powerSupply) {
            this.formnoOuterWorkPlan.powerSupply = "-";
          }
          if (!this.formnoOuterWorkPlan.preview) {
            this.formnoOuterWorkPlan.preview = "-";
          }
          if (!this.formnoOuterWorkPlan.jointTime) {
            this.formnoOuterWorkPlan.jointTime = "-";
          }
          if (!this.formnoOuterWorkPlan.runningTrains) {
            this.formnoOuterWorkPlan.runningTrains = "-";
          }
          console.log(this.formnoOuterWorkPlan);
          this.open = false;
          this.formnoOuterWorkPlan.id = tableId++;

          let params = {};
          params = JSON.parse(JSON.stringify(this.formnoOuterWorkPlan));
          this.tableData.push(params);
          this.noOuterData = [...this.tableData];
        }
      });
    },
    // 表单重置
    reset() {
      this.formnoOuterWorkPlan = {
        carId: null,
        intoTrains: null,
        washingWay: null,
        waterLanes: null,
        trackId: null,
        workTeamId: null,
        jobContent: null,
        powerOutages: null,
        powerSupply: null,
        preview: null,
        jointTime: null,
        runningTrains: null,
        trackIds: null,
      };
      this.trackIds = [];
      this.resetForm("formnoOuterWorkPlan");
    },
    cancelnoOuterWorkPlan() {
      this.open = false;
    },
    cancelOuterWork() {
      this.openplanwork = false;
    },
    // 表单重置
    resetOuter() {
      this.formOuterWork = {
        carId: null,
        intoTrains: null,
        washingWay: null,
        waterLanes: null,
        trackId: null,
        workTeamId: null,
        jobContent: null,
        powerOutages: null,
        powerSupply: null,
        preview: null,
        jointTime: null,
        runningTrains: null,
        trackIds: null,
      };
      this.OuttrackIds = [];
      this.resetForm("formOuterWork");
    },
    handleAdd() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.ways == "look") {
            this.$router.push({
              name: "workPlan",
            });
          } else {
            this.form.shift = this.shift;
            this.noOuterData.forEach((item) => {
              if (item.trackId instanceof Array) {
                item.trackId = item.trackId.join(",");
              }
            });
            this.OuterData.forEach((item) => {
              if (item.trackId instanceof Array) {
                item.trackId = item.trackId.join(",");
              }
            });
            this.form.noOuterWorkPlanDetails = this.noOuterData;
            this.form.outerWorkPlanDetails = this.OuterData;

            if (!this.selectIds) {
              addWorkPlan(this.form).then((res) => {
                console.log(res);
                if (res.code == 200) {
                  this.$modal.msgSuccess("新增成功");
                  this.$router.push({
                    name: "workPlan",
                  });
                }
              });
            } else {
              updateWorkPlan(this.form).then((res) => {
                console.log(res);
                if (res.code == 200) {
                  this.$modal.msgSuccess("修改成功");
                  this.$router.push({
                    name: "workPlan",
                  });
                }
              });
            }
          }
        }
      });
    },
    handleCancel() {
      this.$router.push({
        name: "workPlan",
      });
    },
    AddPlans() {
      this.openplanwork = true;
      this.resetOuter();
      this.getchoiceList();
      this.getworkTeamchoice();
      this.gettrackTeam();
    },
    NoneAddPlans() {
      this.open = true;
      this.reset();
      this.getchoiceList();
      this.getworkTeamchoice();
      this.gettrackTeam();
    },
    //编组号下拉框
    getchoiceList() {
      choiceList().then((res) => {
        this.choiceLists = res.rows;
      });
    },
    // 作业班组下拉框
    getworkTeamchoice() {
      workTeamchoice().then((res) => {
        this.workTeamchoiceLists = res.rows;
      });
    },
    //股道台位下拉框
    gettrackTeam() {
      trackTeam().then((res) => {
        this.trackTeamLists = res.rows;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.worksplans {
  display: flex;
  justify-content: space-between;
  .palnscontents {
    text-align: center;
    margin: 25px 0;
  }
}
.titlesplan {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  border-bottom: 1px solid #ccc;
  padding-bottom: 10px;
}
.titlesplanTwo {
  margin-top: 10px;
}
.buttonsplan {
  margin-left: 20px;
}
.secondTitle {
  margin: 10px 0;
  border-bottom: 1px solid #ccc;
  padding-bottom: 10px;
}
.footersPlan {
  display: flex;
  justify-content: space-between;
}
</style>
